
'use strict';
const app = require('tcb-admin-node');
const tcb_config = {env: 'meatom04-01-2gue0fnr49a26808'};
app.init(tcb_config).auth();
const db = app.database();

let event_param
function getVerList(param){
    event_param = param
    let pageNum = 10
    if(event_param.pageNum && event_param.pageNum != pageNum){
        pageNum = event_param.pageNum
    }
    let page = 0
    if(event_param.page && event_param.page != page){
      page = event_param.page
    }
    return db.collection("Version").where({
      platform : event_param.platform
    }).skip(page * pageNum).limit(pageNum).orderBy("last_time","desc").get().then(res => {
      if(res.data && res.data.length < pageNum){
        res.over = true // 已达到上限
      }
      return res
    })
}

exports.main = async (event, context, callback) => {
  return await getVerList(event)
};
